﻿<UserControl x:Class="Epi.WPF.Dashboard.Controls.DataFilterControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
             xmlns:Controls="clr-namespace:Epi.WPF.Dashboard.Controls"
             mc:Ignorable="d" 
             xmlns:EpiDashboard="clr-namespace:Epi.WPF.Dashboard">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../ResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <Rectangle Fill="White" Style="{DynamicResource shadowRectangleWhite}"></Rectangle>
        <Border Name="borderAll" CornerRadius="0" Style="{DynamicResource mainGadgetBorder}" >
            <Grid x:Name="ConfigGrid" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="5,5,5,5" >
                <!--<Rectangle Fill="#22000000" RadiusX="10" RadiusY="10" Margin="0,4,0,0" />
                <Rectangle Fill="#775C90B2" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0,0,0,5" />
                <Rectangle Fill="#DDFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="5,5,5,10" />-->
                <Grid Name="grdAll" Margin="7" HorizontalAlignment="Center" VerticalAlignment="Top" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="0"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition x:Name="rowSpacer2" Height="0"/>
                        <RowDefinition x:Name="rowAdvanced" Height="Auto"/>
                        <RowDefinition x:Name="rowSpacer3" Height="0"/>
                    </Grid.RowDefinitions>

                    <TextBlock x:Name="txtTitle" HorizontalAlignment="Left" TextAlignment="Center" VerticalAlignment="Center" Text="Data Filters" Margin="-3,0,0,-80" FontWeight="Bold" />

                    <Grid Name="grdSelectionProperties" Grid.Row="0" Width="Auto" HorizontalAlignment="Center" Margin="27,2,2,2" Visibility="Visible">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="7"/>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="12"/>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="90"/>
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="70"/>
                            <ColumnDefinition Width="120"/>
                            <ColumnDefinition Width="120"/>
                            <ColumnDefinition Width="90"/>
                            <ColumnDefinition Width="25"/>
                            <ColumnDefinition Width="90"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="Data filters:" Margin="0,5,0,0" Grid.Row="5" Grid.Column="0"  Grid.ColumnSpan="2" />
                        <ListBox x:Name="lbxConditions" HorizontalAlignment="Left" Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6" Width="514" Visibility="Collapsed"/>

                        <toolkit:DataGrid x:Name="dgFilters" 
                                      Width="514" 
                                      HorizontalAlignment="Left" 
                                      HorizontalScrollBarVisibility="Hidden" 
                                      Grid.Row="6" 
                                      Grid.Column="0" 
                                      Grid.ColumnSpan="6"                                       
                                      CanUserReorderColumns="False" 
                                      CanUserResizeColumns="True" 
                                      CanUserResizeRows="False" 
                                      CanUserSortColumns="False"                                       
                                      CanUserAddRows="False" 
                                      CanUserDeleteRows="False"
                                      RowHeaderWidth="17" RowHeight="17" IsReadOnly="True" SelectionMode="Single" />



                        <TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="Field Name:" Margin="0,5,0,0" Grid.Row="0" Grid.Column="1"  />
                        <ComboBox x:Name="cbxFieldName" HorizontalAlignment="Left" SelectedIndex="0" Grid.Row="1" Grid.Column="1" MaxWidth="110" Width="110" SelectionChanged="cbxFieldName_SelectionChanged" />

                        <TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="Operator:" Margin="0,5,0,0" Grid.Row="0" Grid.Column="2"  />
                        <ComboBox x:Name="cbxOperator" HorizontalAlignment="Left" SelectedIndex="0" Grid.Row="1" Grid.Column="2" MaxWidth="110" Width="110" SelectionChanged="cbxOperator_SelectionChanged" />

                        <TextBlock x:Name="txtValue" HorizontalAlignment="Left" TextAlignment="Center" Text="Value:" Margin="0,5,0,0" Grid.Row="0" Grid.Column="3"  />
                        <ComboBox x:Name="cbxValue" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="3" MaxWidth="110" Width="110" IsEditable="True" Grid.ColumnSpan="3"/>

                        <toolkit:DatePicker toolkit:Name="dateValue" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="3" MaxWidth="90" Width="90" Visibility="Hidden" />
                        <TextBox x:Name="tbxNumericValue" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="3" MaxWidth="90" Width="90" Visibility="Hidden" PreviewTextInput="tbxNumericValue_PreviewTextInput" />
                        <TextBox x:Name="tbxValue" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="3" MaxWidth="90" Width="90" Visibility="Hidden" />

                        <TextBox x:Name="tbxLowValue" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="3" MaxWidth="90" Width="90" Visibility="Hidden" PreviewTextInput="tbxNumericValue_PreviewTextInput" />
                        <TextBox x:Name="tbxHighValue" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="5" MaxWidth="90" Width="90" Visibility="Hidden" PreviewTextInput="tbxNumericValue_PreviewTextInput" />

                        <toolkit:DatePicker toolkit:Name="dateLowValue" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="3" MaxWidth="90" Width="90" Visibility="Hidden" />
                        <toolkit:DatePicker toolkit:Name="dateHighValue" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="5" MaxWidth="90" Width="90" Visibility="Hidden" />

                        <TextBlock x:Name="txtAnd" Visibility="Hidden" Text="and" HorizontalAlignment="Center" Grid.Column="4" Grid.Row="1"/>

                        <Button x:Name="btnNewCondition" Width="100" Grid.ColumnSpan="2" Content="Add Filter" Grid.Row="3" HorizontalAlignment="Left" Click="btnNewCondition_Click">
                            <Button.ContextMenu>
                                <ContextMenu>
                                    <MenuItem x:Name="mnuAddWithAnd" Header="Add Condition with AND" Click="mnuAddWithAnd_Click" />
                                    <MenuItem x:Name="mnuAddWithOr" Header="Add Condition with OR" Click="mnuAddWithOr_Click" />
                                </ContextMenu>
                            </Button.ContextMenu>
                        </Button>

                        <StackPanel x:Name="panelAdvanced" Visibility="Collapsed" Grid.Row="10" Grid.Column="0" Grid.ColumnSpan="3" >
                            <TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="Record processing scope:" Grid.ColumnSpan="2"/>
                            <ComboBox x:Name="cbxRecordProcessScope" HorizontalAlignment="Left" MaxWidth="140" Width="140" IsEditable="False" Grid.ColumnSpan="3" SelectionChanged="cbxRecordProcessScope_SelectionChanged" />
                        </StackPanel>

                        <TextBlock HorizontalAlignment="Left" TextAlignment="Center" Text="The value of  " Grid.Row="1" Grid.Column="0" />
                    </Grid>

                    <Grid x:Name="grdGuidedModeButtons" VerticalAlignment="Top" Grid.Row="2" Margin="27, 5, 5, 5">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="115"/>
                            <ColumnDefinition Width="115"/>
                            <ColumnDefinition Width="115"/>
                        </Grid.ColumnDefinitions>

                        <Button x:Name="btnRemoveCondition" Width="100" Grid.ColumnSpan="2" Content="Remove Selected" Grid.Row="0" HorizontalAlignment="Left" Click="btnRemoveCondition_Click" />
                        <Button x:Name="btnClearConditions" Width="100" Grid.ColumnSpan="2" Content="Clear All" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Click="btnClearConditions_Click" />
                        <Button x:Name="btnAdvancedMode" Width="100" Grid.ColumnSpan="2" Content="Advanced Mode" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Left" Click="btnAdvancedMode_Click" />
                    </Grid>

                    <StackPanel Grid.Row="4" x:Name="pnlAdvancedMode" VerticalAlignment="Top" Margin="27, 0, 0, 0">
                        <TextBlock Text="Advanced Filter Mode" FontWeight="Bold" Margin="0, 0, 0, 3" />
                        <TextBlock Text="Type the desired data filter string into the text box below. Several examples are provided:" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left"
                               Margin="0, 0, 0, 3" />

                        <TextBlock Text="  1. Numeric data:   (AGE &gt;= 15) AND (AGE &lt;= 45)" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />
                        <TextBlock Text="  2. Text data:   (LastName LIKE '%sen') OR (LastName = 'Smith')" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />
                        <TextBlock Text="  3. Date data:   (DOB &gt;= #01/01/2000#) AND (DOB &lt;= #12/31/2000 23:59:59#)" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />
                        <TextBlock Text="  4. Boolean data:   (ILL = true)" 
                               TextWrapping="WrapWithOverflow" 
                               Width="500"
                               HorizontalAlignment="Left" />


                        <TextBox x:Name="txtAdvancedFilter" Margin="0, 5, 0, 0" Height="40" TextWrapping="Wrap" MaxWidth="516" TextChanged="txtAdvancedFilter_TextChanged" />
                        <TextBox x:Name="txtAdvancedFilterStatus" IsReadOnly="True" Margin="0, 5, 0, 0" TextWrapping="Wrap" />

                        <Grid x:Name="grdAdvancedModeButtons">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="140"/>
                                <ColumnDefinition Width="140"/>
                            </Grid.ColumnDefinitions>

                            <Grid.RowDefinitions>
                                <RowDefinition Height="10" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="20" />
                            </Grid.RowDefinitions>
                            <Button x:Name="btnApplyAdvancedFilter" Grid.Row="1" Grid.Column="0" Width="120" Content="Apply Filter" HorizontalAlignment="Left" Click="btnApplyAdvancedFilter_Click" />
                            <Button x:Name="btnGuidedMode"          Grid.Row="1" Grid.Column="1" Width="120" Content="Guided Mode" Click="btnAdvancedMode_Click" HorizontalAlignment="Left" />
                        </Grid>


                    </StackPanel>


                </Grid>
            </Grid>
        </Border>
        <Image x:Name="imgClose" Visibility="Collapsed" Source="..\Images\x_over.png" Cursor="Hand" HorizontalAlignment="Right" Margin="7" VerticalAlignment="Top" Stretch="None" />        
    </Grid>
    
</UserControl>
